//Object space normalmap mapper
//Normal maps are assumed to be in object space for this shader

uniform sampler2D Sampler;
uniform mat3 normalMatrix;		//Normal Matrix, ie Inv-Transpose of ModelView Matrix
uniform float normalScale;			//strength of normals
varying vec2 vUVOut;
varying vec3 lightDir;

void main(void)
{
	vec3 N = normalMatrix * normalize(texture2D(Sampler, vUVOut).xyz * 2.0 - 1.0);//Generate Preturbed normal (0 to 1 --> -1 to 1)
	N.xz *= - 1.0;//Blender again	

	vec3 L = lightDir.xyz;//this is for directional light source
	float diffuse = max( 0.0, dot(N,L) );
		
	//gl_FragColor =  normalize(texture2D(Sampler, vUVOut) * 2.0 - 1.0);
	gl_FragColor =  vec4(diffuse,diffuse,diffuse, 1.0);//vec4(L.xyz, 1.0);//texture2D(Sampler, vUVOut);
	//gl_FragColor = vec4(N.x, N.y, N.z,1);//vec4(diffuse, diffuse, diffuse, 1.0);// * vec4(N,1.0);
}

